<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/12/05 22:12:34 $)
// $RCSfile: client_search.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./includes/functions_users.php");
require_once ("./includes/functions_sqlsearch.php");
require_once ("./modules/core/functions_clientsearch.php");


// ======= SEARCH ALL MODULES =======
$_start = fetchmicrotime();
$_searchresults = array();
if ($_POST["searchtype"] == "all")
{
	if ($module->isRegistered(MODULE_KNOWLEDGEBASE))
	{
		$_searchresults = searchKnowledgebase($_POST["searchquery"]);
	}

	if ($module->isRegistered(MODULE_TROUBLESHOOTER))
	{
		$_searchresults = search_merge($_searchresults, searchTroubleshooter($_POST["searchquery"]));
	}

	if ($module->isRegistered(MODULE_DOWNLOADS))
	{
		$_searchresults = search_merge($_searchresults, searchDownloads($_POST["searchquery"]));
	}

} else if ($_POST["searchtype"] == "knowledgebase" && $module->isRegistered(MODULE_KNOWLEDGEBASE)) {
	$_searchresults = searchKnowledgebase($_POST["searchquery"]);
} else if ($_POST["searchtype"] == "troubleshooter" && $module->isRegistered(MODULE_TROUBLESHOOTER)) {
	$_searchresults = searchTroubleshooter($_POST["searchquery"]);
} else if ($_POST["searchtype"] == "downloads" && $module->isRegistered(MODULE_DOWNLOADS)) {
	$_searchresults = searchDownloads($_POST["searchquery"]);
}
$_end = fetchmicrotime();

if (!count($_searchresults))
{
	$template->assign("infomessage", $_SWIFT["language"]["snoresults"]);
}

$template->assign("searchresults", $_searchresults);
$template->assign("sectiontitle", $_SWIFT["language"]["squerypr"].htmlspecialchars($_POST["searchquery"]));
$template->assign("sectiondesc", sprintf($_SWIFT["language"]["stimetakenpr"], number_format(($_end-$_start), 4)));

$template->cache(array('index', 'header', 'footer', 'navbar', 'searchresultdisplay'));

$template->assign("navigation", '<a href="index.php" id="navlink">'.$_SWIFT["language"]["navhome"]."</a>");

$template->assign("backurl", "index.php");

echo $template->displayTemplate("searchresultdisplay");
?>